<?php
namespace Module\Manage;

use Sfsn\Core\Controller\Controller;
use Model\Member;
use Sfsn\Lib\DzCrypt;
use Sfsn\Core\Config;
use Sfsn\Core\Http\Cookie;
class Login extends Controller
{
    public function index()
    {
        $this->display();    
    }
    public function doLogin()
    {
        $model = new Member();      
        
        //数据
        $formData = $model->formData();
        
        //查询数据
        $where = [
            'username'=>$formData['username']
        ];
        $member = $model->where($where)->fetch();
        
        if($member['password']==md5(md5($formData['password']).$member['salt'])){
            unset($member['salt']);
            $key = Config::get('AUTH_KEY');
            $cookie = DzCrypt::encrypt($member,$key);
            Cookie::set('auth', $cookie);
            $this->redirect('Home/index');
        }else{
            $this->error('用户名或密码错误','Login/index');
        }

    }
    public function logout()
    {
       Cookie::remove('auth');
       $this->success('退出成功','Login/index');
    }
    
}
